home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / Net::hostent.Z / Net::hostent
Encoding:
Text File  |  1998-10-28  |  3.9 KB  |  133 lines

  1.  
  2.  
  3.  
  4.      NNNNeeeetttt::::::::hhhhoooosssstttteeeennnntttt((((3333)))) 22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))  NNNNeeeetttt::::::::hhhhoooosssstttteeeennnntttt((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       Net::hostent - by-name interface to Perl's built-in
  10.       gethost*() functions
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.        use Net::hostnet;
  14.  
  15.  
  16.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  17.       This module's    default    exports    override the core
  18.       _g_e_t_h_o_s_t_b_y_n_a_m_e() and _g_e_t_h_o_s_t_b_y_a_d_d_r() functions, replacing
  19.       them with versions that return "Net::hostent"    objects.  This
  20.       object has methods that return the similarly named structure
  21.       field    name from the C's hostent structure from _n_e_t_d_b._h;
  22.       namely name, aliases,    addrtype, length, and addr_list.  The
  23.       aliases and addr_list    methods    return array reference,    the
  24.       rest scalars.     The addr method is equivalent to the zeroth
  25.       element in the addr_list array reference.
  26.  
  27.       You may also import all the structure    fields directly    into
  28.       your namespace as regular variables using the    :FIELDS    import
  29.       tag.    (Note that this    still overrides    your core functions.)
  30.       Access these fields as variables named with a    preceding h_.
  31.       Thus,    $host_obj->name() corresponds to $h_name if you    import
  32.       the fields.  Array references    are available as regular array
  33.       variables, so    for example @{ $host_obj->aliases() } would be
  34.       simply @h_aliases.
  35.  
  36.       The _g_e_t_h_o_s_t()    funtion    is a simple front-end that forwards a
  37.       numeric argument to _g_e_t_h_o_s_t_b_y_a_d_d_r() by way of
  38.       Socket::inet_aton, and the rest to _g_e_t_h_o_s_t_b_y_n_a_m_e().
  39.  
  40.       To access this functionality without the core    overrides,
  41.       pass the use an empty    import list, and then access function
  42.       functions with their full qualified names.  On the other
  43.       hand,    the built-ins are still    available via the CORE::
  44.       pseudo-package.
  45.  
  46.      EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  47.        use Net::hostent;
  48.        use Socket;
  49.  
  50.        @ARGV = ('netscape.com') unless @ARGV;
  51.  
  52.        for $host ( @ARGV ) {
  53.  
  54.           unless ($h = gethost($host)) {
  55.           warn "$0: no such host: $host\n";
  56.           next;
  57.           }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      NNNNeeeetttt::::::::hhhhoooosssstttteeeennnntttt((((3333)))) 22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))  NNNNeeeetttt::::::::hhhhoooosssstttteeeennnntttt((((3333))))
  71.  
  72.  
  73.  
  74.           printf "\n%s is %s%s\n",
  75.               $host,
  76.               lc($h->name) eq lc($host)    ? "" : "*really* ",
  77.               $h->name;
  78.  
  79.           print "\taliases are ", join(", ", @{$h->aliases}), "\n"
  80.               if @{$h->aliases};
  81.  
  82.           if ( @{$h->addr_list} > 1    ) {
  83.           my $i;
  84.           for $addr ( @{$h->addr_list} ) {
  85.               printf "\taddr #%d is [%s]\n", $i++, inet_ntoa($addr);
  86.           }
  87.           }    else {
  88.           printf "\taddress is [%s]\n",    inet_ntoa($h->addr);
  89.           }
  90.  
  91.           if ($h = gethostbyaddr($h->addr))    {
  92.           if (lc($h->name) ne lc($host)) {
  93.               printf "\tThat addr reverses to host %s!\n", $h->name;
  94.               $host = $h->name;
  95.               redo;
  96.           }
  97.           }
  98.        }
  99.  
  100.  
  101.      NNNNOOOOTTTTEEEE
  102.       While    this class is currently    implemented using the
  103.       Class::Struct    module to build    a struct-like class, you
  104.       shouldn't rely upon this.
  105.  
  106.      AAAAUUUUTTTTHHHHOOOORRRR
  107.       Tom Christiansen
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.